const express=require('express')
const app=express()
const Mock=require('mockjs')
app.use(express.static('static'))
// 跨域
app.all('*',(req,res,next)=>{
      res.header("Access-Control-Allow-Origin", "*")
      next()
})
// index文件中 头部搜索框请求
app.get('/index/topSearch',(req,res)=>{
	let result={
		'search':'@cword(2,4)',
		'imgsrc':'/static/img/index_search.png',
		'data':[
			{'id':'@id',title:'@cword(2,4)'},
			{'id':'@id',title:'@cword(2,4)'},
			{'id':'@id',title:'@cword(2,4)'},
			{'id':'@id',title:'@cword(2,4)'},
			{'id':'@id',title:'@cword(2,4)'},
			{'id':'@id',title:'@cword(2,4)'},
			{'id':'@id',title:'@cword(2,4)'},
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result)
	})
})

// index文件中主要分类请求
app.get('/index/mainLists',(req,res)=>{
	let result={
		'data':[
			{'id':'@id',imgsrc:'/static/img/market.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/fruit.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/cake.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/flower.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/medicine.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/new.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/vip.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/help.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/share.png',title:'@ctitle(4)'},
			{'id':'@id',imgsrc:'/static/img/date.png',title:'@ctitle(4)'},
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// index文件中轮播图请求
app.get('/index/swiper',(req,res)=>{
	let result={
		data:[
			{'id':'@id',imgsrc:'/static/img/swiper1.png'},
			{'id':'@id',imgsrc:'/static/img/swiper2.png'},
			{'id':'@id',imgsrc:'/static/img/swiper3.png'},
			{'id':'@id',imgsrc:'/static/img/swiper4.png'},
			{'id':'@id',imgsrc:'/static/img/swiper5.png'},
			{'id':'@id',imgsrc:'/static/img/swiper6.jpg'},
			{'id':'@id',imgsrc:'/static/img/swiper7.png'},
			{'id':'@id',imgsrc:'/static/img/swiper1.png'},
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// index文件中夏日大作战部分请求
app.get('/index/summer',(req,res)=>{
	let result={
		data:[
			{'id':'@id',imgsrc:'/static/img/summer.png'},
			{'id':'@id',imgsrc:'/static/img/summer2.png'},
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

//index文件中的打折部分请求
app.get('/index/sales',(req,res)=>{
	let result={
		data:[
			{'id':'@id',imgsrc:'/static/img/sg.jpg',title:'@cword(4)',text:'@cword(4,5)'},
			{'id':'@id',imgsrc:'/static/img/ill.png',title:'@cword(4)',text:'@cword(4,5)'},
			{'id':'@id',imgsrc:'/static/img/yh.png',title:'@cword(4)',text:'@cword(4,5)'},
			{'id':'@id',imgsrc:'/static/img/wal.png',title:'@cword(4)',text:'@cword(4,5)'},
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// index文件中秒杀部分请求
app.get('/index/seckill',(req,res)=>{
	let result={
		data:[
			{'id':'@id',imgsrc:'/static/img/indexSales1.jpg','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales2.jpg','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales3.png','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales4.jpg','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales5.jpg','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales6.jpg','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales7.png','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales8.jpg','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales9.png','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			{'id':'@id',imgsrc:'/static/img/indexSales10.jpg','shop|1':['华润苏果','沃尔玛','永辉超市'],title:'@cword(3)','nowPrice|1-9.1-2':1.1,'prePrice|10-30.1':12},
			
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 中间的优惠券请求
app.get('/index/coupon',(req,res)=>{
	let result={
		data:[
			{id:'@id',imgsrc:'/static/img/stitck1.png'}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 中间轮播图请求
app.get('/index/swiperSec',(req,res)=>{
	let result={
		data:[
			{id:'@id',imgsrc:'/static/img/static2.jpg'},
			{id:'@id',imgsrc:'/static/img/static3.png'},
			{id:'@id',imgsrc:'/static/img/static4.png'},
			{id:'@id',imgsrc:'/static/img/static2.jpg'},
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 加载店铺请求
app.get('/index/shopLoading',(req,res)=>{
	let result={
		'data|10':[
			{
				'id':'@id',
				'shop|1':[
					{'shopImg':'/static/img/shop1.png','shopName':'沃尔玛-新街口店'},
					{'shopImg':'/static/img/shop2.png','shopName':'华润苏果-羊皮巷店店'},
					{'shopImg':'/static/img/shop3.png','shopName':'永辉超市-茂业天地店'},
					{'shopImg':'/static/img/shop4.png','shopName':'苏果好的便利-太平南路店'},
					{'shopImg':'/static/img/shop5.png','shopName':'全时便利-碑亭巷店'},
					{'shopImg':'/static/img/shop6.png','shopName':'南京鲜丰水果-文昌巷店'},
					{'shopImg':'/static/img/shop7.png','shopName':'百果园-三元巷店'},
					{'shopImg':'/static/img/shop8.png','shopName':'益丰-香铺营'},
					{'shopImg':'/static/img/shop9.png','shopName':'绿地G-凯瑟琳店'},
					{'shopImg':'/static/img/shop10.png','shopName':'85度C-南京龙台南路店'},
				],
				'starsrc|1':['/static/img/star1.png','/static/img/star2.png','/static/img/star3.png','/static/img/star4.png','/static/img/star5.png'],
				'sales|10-1000':10,
				'salesCount':function(){
					return '月销'+this.sales
				},
				'time|1-120':12,
				'times':function(){
					return this.time+'分钟 '
				},
				'distance|1-5000':10,
				'distances':function(){
					if(this.distance>1000){
						return ' '+parseInt(this.distance/100)/10+'km'
					}else{
						return ' '+this.distance+' m'
					}
				},
				'beginPrice|0-30':2,
				'beginSend':function(){
					return '起送¥'+this.beginPrice
				},
				'translate':'基础运输费¥4',
				'dada|1':['达达专送','商家自送','达达专送','达达专送'],
				'sticks|2-5':[
					{
						'stickId':'@id',
						'classes|1':['领券','满减','返券','首单','折扣','买赠'],
						'des':'@cword(8,20)'
					}
				]

			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 商品页面

// 头部 满减请求
app.get('/shop/reduce',(req,res)=>{
	let result={
		'data':{
			shopImg:'/static/img/shop1.png',
			shopName:'沃尔玛-新街口店',
			dada:'达达专送 | ',
			'time|20-120':20,
			'translate':'基础运输费¥4',
			times:function(){
				return this.time+'分钟'
			},
			post:'14天包退,生鲜农产检验严格,购物无忧',
			'sticks|6-10':[
				{
					id:'@id',
					stick:'满减',
					'name':'@cword(4,8)',
					'num1|20-60':30,
					'num2|1':[5,10,15],
					des:function(){
						return this.name+'满'+this.num1+'减'+this.num2
					},
				}
			],
			
		
		}
			
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 头部优惠券请求
app.get('/shop/sticks',(req,res)=>{
	let result={
		'data|3-5':[
			{
				id:'@id',
				'sale|1':[5,7,9],
				'choose|1':['折','元','元','元'],
				'title1|1':['最高可享','满59可用','满69可用','满78可用'],
				'title2':'@cword(6,10)',
				'title3':'领取后当日有效',
				'getStick':'领券'
			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 头部店铺评价请求
app.get('/shop/appraise',(req,res)=>{
	let result={
		'data':{
				id:'@id',
				'score|4.1':2,
				'scoreT':'综合评分',
				'total|5000-9999':200,
				'totalT':'评论数',
				'userImg':'/static/img/user.jpg',
				'userName':'j***b',
				'grade|1-5':'☆',
				'time':'@datetime()',
				'service':'/static/img/service.png',
				'comment':'@cparagraph(1, 3)',
				'zan':'/static/img/zan.png',
				'word1|2-4':[{'id':'@id','word':'@cword(3,6)'}],
				'more':'查看用户的全部评论'
			}
		
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 店铺信息请求
app.get('/shop/info',(req,res)=>{
	let result={
		data:{
			'dayImg':'/static/img/day.png',
			'daySer':'14天包退',
			'num1|1000-9999':1000,
			'count':function(){
				return this.num1+'件'
			},
			'desCount':'商品数量: ',
			'decSigel':'月销单量: ',
			'num2|1-3':2,
			'sigel':function(){
				return this.num2+'万+'
			},
			'num3|1000-8000':400,
			'attention':function(){
				return '关注人数: '+this.num3+'人'
			},
			'time':'营业时间: 09:00-20:00',
			'place':'门店地址: '+'@county(true)',
			'number1':'025'+'@integer(10000000,99999999)',
			'phone':'门店电话: ',
			'seller':'商家资质',
			'server':'举报商家得红包',
			'max':'最高奖'+'@integer(100,200)'+'元'

		}
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 商品列表请求
app.get('/shop/lists',(req,res)=>{
	let result={
		'data|15-30':[
			{
				'id':'@id',
				'title':'@ctitle(4)',
				'children|3-6':[
					{
						'id':'@id',
						'ctitle':'@ctitle(3,5)'
					}

				]
			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 商品详情请求
app.get('/shop/goods',(req,res)=>{
	let result={
		'title':'@cword(4,6)'+'(@integer(8, 15))',
		'data|8-15':[
			{
				'id':'@id',
				'imgsrc':'/static/img/goods'+'@pick(["1", "2", "3", "4", "5", "6", "7", "8", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21","22"])'+'.jpg',
				'title1':'@cword(7,10)',
				'salesCount':'月销'+'@integer(50, 100)'+'件 | 好评'+'@integer(75, 100)'+'%',
				'type|1':['秒杀','直降','','','','',''],
				'price|10-50.0-1':10,
				'prePrice':function(){
					return this.price+15
				},
				'num':0,
				'store|1-5':2,
				'check':true
			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result)
	})
})

// 分类列表请求
app.get('/list/classify',(req,res)=>{
	let result={
		'data|8-12':[
			{
				id:'@id',
				title:'@cword(4)'
			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})
// 分类详情请求
app.get('/list/details',(req,res)=>{
	let result={
		'data|1-2':[
			{
				id:'@id',
				title:'@cword(2,4)',
				'children|6':[
					{
						id:'@id',
						imgsrc:'/static/img/list'+'@natural(1,24)'+'.jpg',
						'ctitle':'@cword(2,4)'
					}
				]
			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 购物车页面详情请求
app.get('/cart/details',(req,res)=>{
	let result={
		'data|1-2':[
			{
				id:'@id',
				'title':'@cword(6)',
				'children|1-2':[
					{
						id:'@id',
						'shop|1':['沃尔玛-新街口店','华润苏果-羊皮巷店店','永辉超市-茂业天地店','全时便利-碑亭巷店'],
						'imgsrc|3-5':[
							{
								id:'@id',
								imgs:'/static/img/list'+'@natural(1,24)'+'.jpg',
								'cprice':'¥'+'@float(10,30,1,1)'
							}
						],
		
					}
				]
			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})


// 订单页面的请求
app.get('/order/list',(req,res)=>{
	let result={
		'data|1-2':[
			{
				id:'@id',
				'shop|1':['沃尔玛-新街口店','华润苏果-羊皮巷店店','永辉超市-茂业天地店','全时便利-碑亭巷店'],
				'status':'已完成',
				'time':'@date',
				'imgs|2-4':[
					{
						id:'@id',
						imgsrc:'/static/img/order'+'@natural(1,8)'+'.jpg'
					},
				],
				'price':'¥'+'@float(10,50,1,1)',
				'count':'共'+'@natural(2,4)'+'件',
				'send':'达达专送',
				
			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 我的分类请求
app.get('/mine/list',(req,res)=>{
	let result={
		data:{
				id:'@id',
				imgSrc:'/static/img/mypic.png',
				'children|8-10':[
					{
						id:'@id',
						cimg:'/static/img/mine'+'@natural(1,11)'+'.png',
						ctitle:'@cword(4)'
					}
				]
			}
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result).data
	})
})

// 注册页面的协议请求
app.get('/register/protocol',(req,res)=>{
	let result={
		title:'@ctitle(9)',
		content:'@cparagraph(28)',
		agreen:'@cparagraph(3)'
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result)
	})
})

// 详情页面的请求
app.get('/details/title',(req,res)=>{
	let result={
		title:'@cword(16,20)',
		title2:'@cword(8,10)',
		'price|100-130.1':100,
		imgs:[
			{
				id:'@id',
				imgSrc:'/static/img/details1.jpg'
			},
			{
				id:'@id',
				imgSrc:'/static/img/details2.jpg'
			},
			{
				id:'@id',				
				imgSrc:'/static/img/details3.jpg'
			},
			{
				id:'@id',				
				imgSrc:'/static/img/details4.jpg'
			},
			{
				id:'@id',				
				imgSrc:'/static/img/details5.jpg'
			},
			{
				id:'@id',				
				imgSrc:'/static/img/details6.jpg'
			}
		]
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result)
	})
})

// 详情页面的商家部分请求
app.get('/details/shop',(req,res)=>{
	let result={
		'shop|1':['沃尔玛','永辉超市','华润苏果'],
		'word':'@cword(3,4)',
		shopName:function(){
			return this.shop+'-'+this.word+'店'
		},
		'link':'联系商家',
		'assess|1-1000':2,
		'goodassess':'好评'+'@natural(95,100)'+'%'
	}
	res.send({
		error:0,
		message:'it is ok',
		data:Mock.mock(result)
	})
})

app.listen('8088',()=>{
      console.log('8088端口启动完成')
})